package cn.wolfcode.shop.controller;

import cn.wolfcode.shop.domain.PropertyValue;
import cn.wolfcode.shop.service.IPropertyValueService;
import cn.wolfcode.shop.vo.JSONResultVo;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by wolfcode on 2018/8/17.
 */
@Controller
public class PropertyValueController {
    @Reference
    private IPropertyValueService propertyValueService;
    @RequestMapping("/propertyValue/get/{propertyId}")
    public String propertyValuePage(@PathVariable("propertyId") Long propertyId, Model model){
        model.addAttribute("propertyValueList",propertyValueService.queryByPropertyId(propertyId));
        return "property/property_value_list";
    }
    @RequestMapping("/propertyValue/save")
    @ResponseBody
    public JSONResultVo saveOrUpdateBatch(@RequestBody List<PropertyValue> propertyValueList){
        JSONResultVo vo = new JSONResultVo();
        try{
            propertyValueService.saveOrUpdateBatch(propertyValueList);
        }catch(Exception ex){
            ex.printStackTrace();
            vo.setErrorMsg(ex.getMessage());
        }
        return vo;
    }
    @RequestMapping("/propertyValue/delete/{propertyValueId}")
    @ResponseBody
    public JSONResultVo delete(@PathVariable("propertyValueId") Long propertyValueId){
        JSONResultVo vo = new JSONResultVo();
        try{
            propertyValueService.delete(propertyValueId);
        }catch(Exception ex){
            ex.printStackTrace();
            vo.setErrorMsg(ex.getMessage());
        }
        return vo;
    }
}
